<?php

    class Tools{
        public static function getTime($tag){
            list($usec,$sec)=explode(" ", microtime());
            $now_time=((float)$usec+(float)$sec);
            list($usec,$sec)=explode(".", $now_time);
            $date=date($tag,$usec);
            return str_replace('x', $sec, $date);
        }

    static function guid(){
            if (function_exists('com_create_guid')){
                return com_create_guid();
            }else{
                mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
                $charid = strtoupper(md5(uniqid(rand(), true)));
                $hyphen = chr(45);// "-"
                $uuid = chr(123)// "{"
                    .substr($charid, 0, 8).$hyphen
                    .substr($charid, 8, 4).$hyphen
                    .substr($charid,12, 4).$hyphen
                    .substr($charid,16, 4).$hyphen
                    .substr($charid,20,12)
                    .chr(125);// "}"
                return $uuid;
            }
        }
    static function  create_uuid($prefix = ""){    //可以指定前缀
            $str = md5(uniqid(mt_rand(), true));
            $uuid  = substr($str,0,8) . '-';
            $uuid .= substr($str,8,4) . '-';
            $uuid .= substr($str,12,4) . '-';
            $uuid .= substr($str,16,4) . '-';
            $uuid .= substr($str,20,12);
            return $prefix . $uuid;
        }
    }